package com.tracy.lifeproject.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.tracy.lifeproject.R;
import com.tracy.lifeproject.utils.CommonAdapter;
import com.tracy.lifeproject.utils.MyHolder;
import com.tracy.lifeproject.utils.PicassoRoundTransform;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

public class LookMoreActivity extends AppCompatActivity {

    @InjectView(R.id.img_sum_back)
    ImageView mImgSumBack;
    @InjectView(R.id.btn_sum_back)
    Button mBtnSumBack;
    @InjectView(R.id.summer_recycler)
    RecyclerView mSummerRecycler;
    private Activity mActivity = this;
    private ArrayList<String> mMUrlList;
    private ArrayList<String> mTitle;
    private ArrayList<String> mSubtitle;
    private ArrayList<String> mIdList;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_look_more);
        ButterKnife.inject(this);
        Intent intent = getIntent();
        mMUrlList = intent.getStringArrayListExtra("url");
        mTitle = intent.getStringArrayListExtra("title");
        mSubtitle = intent.getStringArrayListExtra("subtitle");
        mIdList=intent.getStringArrayListExtra("id");

        for (int i = 0; i < mMUrlList.size(); i++) {
            String s = mMUrlList.get(i);
            String s1 = mTitle.get(i);
            String s2 = mSubtitle.get(i);
            Log.i("123", "传递的地址----》" + s + "----->" + s1 + "------->" + s2);
        }

        mSummerRecycler.setAdapter(new CommonAdapter(this, mMUrlList, R.layout.look_more_item) {
            @Override
            public void bindData(MyHolder holder, final int position, Object bean) {
                ImageView iv = holder.getViewById(R.id.img_more);
                Picasso.with(mActivity).load(mMUrlList.get(position))
                        .transform(new PicassoRoundTransform())
                        .into(iv);
                holder.setText(mTitle.get(position),R.id.item_title)
                        .setText(mSubtitle.get(position),R.id.subtitle);

                /**
                 * 单项点击跳转
                 * */
                String str = mIdList.get(position);
                final int id = Integer.parseInt(str);
                iv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent1 = new Intent(mActivity, SummerActivity.class);
                        intent1.putExtra("id",id);
                        startActivity(intent1);
                    }
                });

            }
//            @Override
//            public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
//
//            }
        });

        mSummerRecycler.setLayoutManager(new LinearLayoutManager(mActivity));
    }

    @OnClick({R.id.img_sum_back, R.id.btn_sum_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_sum_back:
                finish();
                break;
            case R.id.btn_sum_back:
                finish();
                break;
        }
    }
}
